#include "GaussianDistribution.h"

GaussianDistribution::GaussianDistribution(double mean, double deviation) {
    generator = new boost::random::random_device;
    distribution = new boost::normal_distribution<double>(mean, deviation);
    variate_generator = new boost::variate_generator < boost::random::random_device&, boost::normal_distribution<double> >(*generator, *distribution);
}

GaussianDistribution::~GaussianDistribution() {
    delete variate_generator;
    delete distribution;
    delete generator;
}

double GaussianDistribution::Sample() {
    return variate_generator->operator ()(); //mesmo que return (*var_nor)();
}

double GaussianDistribution::mean() {
    return distribution->mean();
}

double GaussianDistribution::sigma() {
    return distribution->sigma();
}

/**
 * Retorna um double ~ N(mean, deviation)
 * @param mean média
 * @param deviation desvio padrão
 * @return um double ~ N(mean, deviation)
 */
double GaussianDistribution::rand(double mean, double deviation) {
    GaussianDistribution * obj = new GaussianDistribution(mean, deviation);
    double d = obj->Sample();
    delete obj;
    return d;
}
